import { inject, provide, reactive } from "vue";
import type { MessageState } from "./types";

export * from "./types";

/**
 * 默认 MessageState
 */
export function defaultMessageState(): MessageState {
    return {
        visible: false,
        text: "",
        timeout: 3000,
        closeable: true,
    };
}

/**
 * 提供 MessageState
 */
export function provideMessageState(): MessageState {
    const messageState = reactive(defaultMessageState());

    provide("MessageState", messageState);

    return messageState;
}

/**
 * 注入 MessageState
 */
export function injectMessageState(): MessageState {
    return inject("MessageState", defaultMessageState());
}
